package com.zxing.spring.gateway.filter;

import com.zxing.spring.gateway.config.Constant;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;
import java.util.List;

@Component
@Slf4j
public class IgnoreAuthFilterFactory extends AbstractGatewayFilterFactory{

    @Override
    public List<String> shortcutFieldOrder() {
        return Arrays.asList("parts");
    }

    @Override
    public GatewayFilter apply(Object config) {
        return (exchange, chain) -> {
            log.debug("--[DEBUG] enter ignore auth filter");
            exchange.getAttributes().put(Constant.IGNORE_AUTH, true);
            return chain.filter(exchange);
        };
    }

    @Override
    public String name() {
        return "IgnoreAuth";
    }
}
